package com.learn.english.mapper;

import com.learn.english.model.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author TISNIW
 * @version 1.0
 * @desc
 */
@Mapper
public interface CourseMapper {
    @Select("select * from course where name like concat('%', #{name}, '%') limit #{pageNum}, #{pageSize}")
    List<Course> selectPage(Integer pageNum, Integer pageSize, String name);

    @Select("select * from course where id = #{id}")
    Course selectById(Integer id);

    @Update({
            "update course set category_id = #{categoryId},",
            "teacher_id = #{teacherId},",
            "name = #{name},",
            "course_url = #{courseUrl},",
            "cover_url = #{coverUrl},",
            "is_free = #{isFree},",
            "cost = #{cost},",
            "count = #{count},",
            "updated_at = now()",
            "where id = #{id}"
    })
    int updateById(Course course);

    @Delete("delete from course where id = #{id}")
    int deleteById(Integer id);
    @Update("update course set course_url = #{courseUrl} where id = #{id}")
    int updateCourseUrlById(Integer id, String courseUrl);
    @Select("select count(*) from course")
    Long getCount();
    @Insert({
            "insert into course " +
                    "(id,name, cover_url, `desc`, course_url) ",
            "values " +
                    "(#{id},#{name}, #{coverUrl}, #{desc}, #{courseUrl})"
    })
    int insert(Course course);
}